#include "zScriptRenderer.hpp"
namespace zzz{
zScriptRenderer::zScriptRenderer()
:loaded(false)
{

}

void zScriptRenderer::LoadRenderScript( const char *filename )
{
  loaded=m_zRS.LoadScript(filename);
  m_zRS.SetVariable("i_width",width_);
  m_zRS.SetVariable("i_height",height_);
  m_zRS.SetVariable("i_zdist",camera_.m_Position[2]);
  if (loaded) m_zRS.DoFunction("<ONCE>");
  Redraw();
}

bool zScriptRenderer::InitData()
{
  ArcBallRenderer::InitData();
  m_zRS.Init(this);
  return true;
}

bool zScriptRenderer::Draw()
{
  if (loaded)
  {
    m_zRS.DoFunction("<REPEAT>");
  }
  else
    MultiObjEnvRenderer::Draw();
  return true;
}

void zScriptRenderer::OnChar( unsigned int nChar, unsigned int nRepCnt, unsigned int nFlags )
{
  MultiObjEnvRenderer::OnChar(nChar,nRepCnt,nFlags);
  m_zRS.OnChar(nChar,nRepCnt,nFlags);
}

void zScriptRenderer::SingleCommand( const string &str )
{
  m_zRS.SingleCommand(str);
}

void zScriptRenderer::OnMouseWheel( unsigned int nFlags, int zDelta, int x,int y )
{
  MultiObjEnvRenderer::OnMouseWheel(nFlags,zDelta,x,y);
  m_zRS.SetVariable("zDist",camera_.m_Position[2]);
}

void zScriptRenderer::OnSize( unsigned int nType, int cx, int cy )
{
  MultiObjEnvRenderer::OnSize(nType,cx,cy);
  m_zRS.SetVariable("i_width",cx);
  m_zRS.SetVariable("i_height",cy);
}
}